import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import loading from './common/js/load.js'
import './assets/css/icon.css'
import Echarts from 'echarts'
import api from './api'

require('./assets/css/common.scss')
require('./mock/index.js')
Vue.config.productionTip = false
Vue.prototype.loading = loading
Vue.prototype.$echarts = Echarts
Vue.prototype.api = api
Vue.use(ElementUI)
Vue.prototype.basePath = 'localhost:8989'
//Vue.prototype.basePath = '192.168.0.138:8989'

Vue.prototype.goIndex = function (route) {
  this.$router.push(route)
}

router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title} | vue-manage-system`
  if (to.meta.isLogin) {
    next('/')
  } else {
    const token = localStorage.getItem('Authorization')
    if ((token == null || token === '') && to.path !== '/login') {
      next({
        path: '/login'
      })
    } else {
      next()
    }
  }
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
